import 'package:demo/pages/components/card_card.dart';
import 'package:demo/pages/models/wallet.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:demo/pages/models/card.dart' as MyCard;

class PersonalPage extends StatefulWidget {
  const PersonalPage({super.key});

  @override
  State<PersonalPage> createState() => _PersonalPageState();
}

class _PersonalPageState extends State<PersonalPage> {
  void removeFromCart(MyCard.Card card) {
    Provider.of<MyWallet>(context, listen: false).removeFromCart(card);
  }

  @override
  Widget build(BuildContext context) {
    return Consumer<MyWallet>(
      builder: (context, value, child) => SafeArea(
        child: Padding(
          padding: const EdgeInsets.all(25),
          child: Column(
            children: [
              const Text(
                'Cart',
                style: TextStyle(fontSize: 25),
              ),
              const SizedBox(height: 25),
              Expanded(
                child: ListView.builder(
                  itemCount: value.cart.length,
                  itemBuilder: (context, index) {
                    Card card = value.cart[index] as Card;
                    return Column(
                      children: [
                        CardCard(
                          cardColor: Colors.white,
                          card: card as MyCard.Card ,
                          onTap: () {
                            removeFromCart(card as MyCard.Card);
                          },
                          trailing: const Icon(Icons.delete),
                        ),
                        const  SizedBox(height: 10)
                      ],
                    );

                  },
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}